/**
 * @file TaskQue.hh
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-08
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "Condition.hh"
#include "MutexLock.hh"
#include <functional>
#include <queue>
using std::queue;

namespace snow
{

using Task = std::function<void()>;
using ElemType = Task;

class TaskQue
{
public:
    TaskQue(size_t size);

    void push(ElemType elem);
    ElemType pop();

    bool full() const;
    bool empty() const;

    void notifyExit(); // 通知notEmpty，线程池要退出了，你别阻塞了

private:
    size_t queSize_;
    queue<ElemType> que_;
    MutexLock mutex_;
    Condition notFull_;
    Condition notEmpty_;
    // 保证队列空时，线程池退出能正常退出，而非阻塞在notEmpty条件变量上
    bool isExit_; // 线程池退出标志位，由线程池安排
};

} // namespace snow